/****************************************************************************
 * 2023.12 DESKTOP-12M00TJ
 ****************************************************************************/

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using QFramework;

namespace ProjectSurvivor
{
	public partial class ExpUpgradePanel : UIElement,IController
	{
		private void Awake()
		{
            var expUpgradeSystem= this.GetSystem<ExpUpgradeSystem>();

            foreach (var expUpgradeItem in expUpgradeSystem.Items)
            {
                BtnExpUpgradeItemTemplate.InstantiateWithParent(UpgradeRoot)
                     .Self(self =>
                     {
                         ExpUpgradeItem itemCache = expUpgradeItem;
                         self.onClick.AddListener(() =>
                         {
                             Time.timeScale = 1.0f;
                             itemCache.Upgrade();
                             this.Hide();
                             AudioKit.PlaySound("AbilityLevelUp");
                         });

                         var selfCache = self;
                         selfCache.Hide();

                         itemCache.Visible.RegisterWithInitValue(visble =>
                         {
                             if (visble)
                             {
                                 selfCache.Show();
                             }
                             else
                             {
                                 selfCache.Hide();
                             }
                         }).UnRegisterWhenGameObjectDestroyed(selfCache);

                         itemCache.CurrentLevel.RegisterWithInitValue(lv =>
                         {
                             selfCache.GetComponentInChildren<Text>().text=itemCache.Description;
                         }).UnRegisterWhenGameObjectDestroyed(gameObject);

                     });
            }

            //UpgradeRoot.Hide();

            //BtnUpgrade.onClick.AddListener(() =>
            //{
            //	Time.timeScale = 1;
            //	Global.SimpleAbilityDamage.Value *= 1.5f;
            //            UpgradeRoot.Hide();
            //	AudioKit.PlaySound("AbilityLevelUp");
            //         });

            //BtnSimpleDurationUpgrade.onClick.AddListener(() =>
            //{
            //             Time.timeScale = 1;
            //             Global.SimpleAbilityDuration.Value *= 0.8f;
            //	UpgradeRoot.Hide();
            //             AudioKit.PlaySound("AbilityLevelUp");
            //         });
        }

        protected override void OnBeforeDestroy()
		{
		}

        public IArchitecture GetArchitecture()
        {
            return Global.Interface;
        }
    }
}